package com.tangsm.spring.boot.deferred.result.controller;

import com.tangsm.spring.boot.deferred.result.domain.vo.Result;
import com.tangsm.spring.boot.deferred.result.service.TaskService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 阻塞调用请求控制器
 *
 * @author tangsm
 */
@RestController
@RequestMapping("/block")
public class BlockController {
    private static final Logger log = LoggerFactory.getLogger(BlockController.class);

    @Autowired
    private TaskService taskService;

    /**
     * 阻塞调用
     * @return 响应结果
     */
    @GetMapping(value = "/get")
    public Result<String> getResult() {
        log.info("接收请求，开始处理...");

        Result<String> result = taskService.getResult();

        log.info("接收任务线程完成并退出");
        return result;
    }
}
